package array;

public class Solution_53 {
    /**
     * 注意标准前缀和写法
     */
    public int maxSubArray(int[] nums) {
        int[] s = new int[nums.length+1];
        s[0] = 0;
        for (int i = 0; i < nums.length; i++) {
            s[i + 1] = s[i] + nums[i];
        }
        int minSum = 0, res = Integer.MIN_VALUE / 2;
        for (int i = 1; i < s.length; i++) {
            res = Math.max(res, s[i] - minSum);
            minSum = Math.min(minSum, s[i]);
        }
        return res;
    }
}
